home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DESDOS.ARJ / UUENCODE.C < prev    next >
C/C++ Source or Header  |  1989-01-30  |  1KB  |  41 lines

  1. /* uuencode.c - convert files to ascii-encoded form
  2.  * Usage: uuencode [filename] < infile
  3.  *
  4.  * If [filename] isn't specified, "/dev/stdout" is the default.  This allows
  5.  * use of my uudecode as a pipeline filter.
  6.  *
  7.  * Written and placed in the public domain by Phil Karn, KA9Q
  8.  * 31 March 1987
  9.  */
  10. #include <stdio.h>
  11. #define    LINELEN    45
  12. main(argc,argv)
  13. int argc;
  14. char *argv[];
  15. {
  16.     char linebuf[LINELEN];
  17.     register char *cp;
  18.     int linelen;
  19.  
  20.     if(argc > 1)
  21.         printf("begin 0666 %s\n",argv[1]);
  22.     else
  23.         printf("begin 0666 /dev/stdout\n");
  24.     for(;;){
  25.         linelen = fread(linebuf,1,LINELEN,stdin);
  26.         if(linelen <= 0)
  27.             break;
  28.         putchar(' ' + linelen);    /* Record length */
  29.         for(cp = linebuf; cp < &linebuf[linelen]; cp += 3){
  30.                 putchar(' ' + ((cp[0] >> 2) & 0x3f));
  31.             putchar(' ' + (((cp[0] << 4) & 0x30) | ((cp[1] >> 4) & 0xf)));
  32.             putchar(' ' + (((cp[1] << 2) & 0x3c) | ((cp[2] >> 6) & 0x3)));
  33.             putchar(' ' + (cp[2] & 0x3f));
  34.         }
  35.         putchar('\n');
  36.     }
  37.     printf(" \n");    /* 0-length null record */
  38.     printf("end\n");
  39. }
  40.  
  41.